Skip to content

Generator: share repeated code, no change to the generated text - #303

Merged
electricessence merged 1 commit into
masterfrom
refactor/generator-shared
Dec 2, 2026
Merged

electricessence merged 1 commit into
masterfrom
refactor/generator-shared

Conversation

@electricessence

Copy link
Copy Markdown
Collaborator

A refactor of the source generator's own code. The text it emits is byte-identical to before. No public API changes and nothing at run time: the generator runs at build time, and the code it generates is the same.

What changed

  • The first line of a partial model's Bind is appended as a line of its own, not through a placeholder that only lined up with the tabs after it.
  • A member's read statement takes its ordinal as a parameter; the two-step replacement of a second placeholder is gone.
  • The fully qualified symbol display format is declared once, on ModelReader.
  • One helper says whether a type is Nullable<T> and one returns its underlying type; the three places that spelled it out use them.
  • One helper tells whether a member or parameter carries a null policy or null value attribute.
  • One iterator walks a type and its base types; the four loops that did it by hand use it.
  • EquatableArray drops its length, indexer and enumerator, which nothing used. Items, Equals and GetHashCode, which the incremental cache relies on, are unchanged.

Looked at and left alone

  • The two query-receiver tests in the interceptor each appear once, with different sets, so a helper would only add lines.
  • The public-setter pattern appears twice as a one-clause test and a third time inside a pattern a helper cannot replace; a helper would be longer than the code.
  • The empty-string sentinel is commented where it is made and lives in the cached site model; null would gain nothing.

The net is +1 line (49 added, 48 removed): this removes repeated spellings, not code.

Checks

  • The generated files (the generator tests with the counters on and off, and the generated benchmarks) were written before and after the change and compared with a recursive diff: empty.
  • Generator tests 189 of 189 pass; Release 15,990 and Debug 15,969 Core tests pass (16 skipped), 0 build warnings, 255 sample checks, VS MSBuild 0 errors, dotnet format style and analyzers clean on all 28 checks, DocFX 0 warnings, the style scan clean.

🤖 Generated with Claude Code

A refactor of the source generator's own code. The text it emits is
byte-identical to before: the generated file of the generator tests (counters
on and off) and of the generated benchmarks, compared with a recursive diff
before and after, is empty.

What changed:

- The first line of a partial model's Bind is appended as a line of its own,
  not through a placeholder that only lined up with the tabs after it.
- A member's read statement takes its ordinal as a parameter. The two-step
  replacement of a second placeholder is gone.
- The fully qualified symbol display format is declared once, on ModelReader.
- One helper says whether a type is Nullable<T> and one returns its underlying
  type; the three places that spelled it out use them.
- One helper tells whether a member or parameter carries a null policy or null
  value attribute.
- One iterator walks a type and its base types; the four loops that did it by
  hand use it.
- EquatableArray drops its length, indexer and enumerator, which nothing used.
  Items, Equals and GetHashCode, which the incremental cache relies on, are
  unchanged.

Looked at and left alone:

- The two query-receiver tests in the interceptor are not repeated (each
  appears once, with different sets), so a helper would only add lines.
- The public-setter pattern appears twice as a one-clause test and a third
  time inside a pattern a helper cannot replace; the helper would be longer
  than the code it replaces.
- The empty strings Site carries for a typed query are documented where they
  are made and sit in the cached model; changing them gains nothing.

Checks: whole solution Release build without warnings; generator tests and
core tests in Release; dotnet format style and analyzers on the generator and
its tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@electricessence
electricessence merged commit 1702507 into master Dec 2, 2026
9 checks passed
@electricessence
electricessence deleted the refactor/generator-shared branch December 2, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant